import _slicedToArray from '@babel/runtime/helpers/esm/slicedToArray';
import { useCallback, useEffect, useState } from 'react';
export default (function (options) {
  var _useState = useState(Array.isArray(options) ? options : []),
    _useState2 = _slicedToArray(_useState, 2),
    innerOptions = _useState2[0],
    setInnerOptions = _useState2[1];
  var fetchOptions = useCallback(
    function (params) {
      if (typeof options === 'function') {
        return options(params).then(function (data) {
          setInnerOptions(data);
        });
      }
    },
    [options],
  );
  useEffect(
    function () {
      if (typeof options === 'function') {
        fetchOptions();
      } else if (Array.isArray(options)) {
        setInnerOptions(options);
      }
    },
    [options],
  );
  return {
    options: innerOptions,
    setOptions: setInnerOptions,
    fetchOptions: fetchOptions,
  };
});
